﻿using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfMyText.VM;
namespace WpfMyText.UC
{
    /// <summary>
    /// UserSettingUC.xaml 的交互逻辑
    /// </summary>
    public partial class UserSettingUC : UserControl
    {
        private UserSettingUCVM vm = new UserSettingUCVM();

        public UserSettingUC()
        {
            InitializeComponent();
            App app = (App)App.Current;
            FontFamilyComboBox.SelectedValue= app.TextFontFamily;
            this.DataContext = vm;

        }

        private void FontFamilyComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {

            App app = (App)Application.Current;
            app.SaveUserProperties();


            Window parentWindow = Window.GetWindow(this);
            if (parentWindow != null)
            {
                parentWindow.Close();
            }

        }
    }
    public class UserSettingUCVM:INotifyPropertyChanged
    {
        public UserSettingUCVM()
        {
            StartWW = WindowWidth;
             StartWH = WindowHeight;
        }
        public void  ResetWindow()
        {
            WindowWidth = StartWW;
            WindowHeight = StartWH;
        }
        public double StartWW { get; set; }
        public double StartWH { get; set; }


        public bool isWindowChange=false;

        public double TextFontSize
        {
            get
            {
                return ((App)Application.Current).TextFontSize;
            }
            set
            {
                ((App)Application.Current).TextFontSize = value;
                OnPropertyChanged();

            }

        }
        public object TextFontFamily
        {
            get
            {
                return ((App)Application.Current).TextFontFamily;
            }
            set
            {
                ((App)Application.Current).TextFontFamily = value;
                OnPropertyChanged();
            }
        }

        public Color BackgroundColor
        {
            get
            {
                return ((App)Application.Current).BackgroundColor;
            }
            set
            {
                ((App)Application.Current).BackgroundColor = value;
                OnPropertyChanged();
            }


        }

        public double WindowHeight
        {
            get { return ((App)Application.Current).WindowHeight; }
            set { 
                ((App)Application.Current).WindowHeight = value;
                isWindowChange = true;
                OnPropertyChanged(); }
        }
        public double WindowWidth
        {
            get { return ((App)Application.Current).WindowWidth; }
            set { ((App)Application.Current).WindowWidth = value; 
                
                isWindowChange = true;
                OnPropertyChanged(); }
        }

        public double BackgroundOpacity
        {
            get
            {
                return ((App)Application.Current).BackgroundOpacity;
            }
            set
            {
                ((App)Application.Current).BackgroundOpacity = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
